# -*- coding:utf-8 -*-
# @author='dapeng',
# @version='1.0.0',
from voice.alivoice import say,saytail,getvoice
from api.api import *
from talk import robot
from movie import movie
from music import netease
from image import bakground
from zhihu import zhihu
from sina import weibo
from api import tianxingapi, alapi

help = '''
========功能=======
修改群公告 新公告 （需要群管理权限）
看电视 | 电视直播
语音 小美说今晚我家没人
壁纸 | 高清壁纸
二次元
点歌 热爱105
强制点歌 热爱105
分享歌曲 热爱105
豆瓣分类
豆瓣 喜剧 1
电视剧 二炮手 5
斗鱼直播
虎牙直播
知乎日报
知乎历史
微博热点
微博前10
文案
互删
脑筋急转弯
经典台词
彩虹屁
猜字谜
猜成语
猜广告语
故事
雷人笑话
绕口令
顺口溜
土情话
舔狗日记
早报
藏头诗
每日一文
随机美文
今日热榜
'''

#处理群消息
def handlemsg(robot_wxid, to_wxid, final_from_wxid, final_nickname, msg):
    # 修改群公告
    if msg.startswith("修改群公告"):
        modify_group_notice(robot_wxid, to_wxid, msg.replace("修改群公告", '').strip())
    elif msg == 'help' or msg == '功能' or msg == '帮助':
        send_text_msg(robot_wxid,to_wxid,help)
    elif msg == '菜单':
        send_text_msg(robot_wxid, to_wxid, str(robot.gongneng()))
    elif msg == '斗鱼' or msg == '斗鱼直播':
        send_link_msg(robot_wxid, to_wxid, "直播", '斗鱼直播', 'https://www.douyu.com/', '')
    elif msg == '虎牙' or msg == '虎牙直播':
        send_link_msg(robot_wxid, to_wxid, "直播", '虎牙直播', 'https://www.huya.com/', '')
    elif msg == '看电视' or msg.startswith('电视直播'):
        send_link_msg(robot_wxid, to_wxid, "央视直播", 'CCTV-1', 'https://tv.cctv.com/live/cctv1', '')
    elif msg == '知乎日报':
        send_text_msg(robot_wxid, to_wxid, zhihu.newszhihu())
    elif msg=='微博热点' or msg=='新浪微博':
        send_text_msg(robot_wxid, to_wxid, weibo.xinlang())
    elif msg=='微博前10' or msg=='热点前10':
        send_text_msg(robot_wxid, to_wxid, weibo.xinlang10())
    elif msg == '文案':
        send_text_msg(robot_wxid, to_wxid, tianxingapi.topic())
    elif msg == '早报':
        send_text_msg(robot_wxid, to_wxid, alapi.zaobao())
    elif msg == '今日热榜':
        send_text_msg(robot_wxid, to_wxid, alapi.hot())
    elif msg == '每日一文':
        send_text_msg(robot_wxid, to_wxid, alapi.mryw())
    elif msg == '随机美文':
        send_text_msg(robot_wxid, to_wxid, alapi.mrywrandom())
    elif msg == '互删':
        send_text_msg(robot_wxid, to_wxid, tianxingapi.delete())
    elif msg == '脑筋急转弯':
        send_text_msg(robot_wxid, to_wxid, tianxingapi.naowan())
    elif msg == '经典台词':
        send_text_msg(robot_wxid, to_wxid, tianxingapi.dialogue())
    elif msg == '彩虹屁':
        send_text_msg(robot_wxid, to_wxid, tianxingapi.caihongpi())
    elif msg == '猜字谜':
        send_text_msg(robot_wxid, to_wxid, tianxingapi.zimi())
    elif msg == '猜成语':
        send_text_msg(robot_wxid, to_wxid, tianxingapi.caichengyu())
    elif msg == '猜广告语':
        send_text_msg(robot_wxid, to_wxid, tianxingapi.slogan())
    elif msg == '故事':
        send_text_msg(robot_wxid, to_wxid, tianxingapi.story())
    elif msg == '雷人笑话':
        send_text_msg(robot_wxid, to_wxid, tianxingapi.joke())
    elif msg == '绕口令':
        send_text_msg(robot_wxid, to_wxid, tianxingapi.rkl())
    elif msg == '土情话':
        send_text_msg(robot_wxid, to_wxid, tianxingapi.saylove())
    elif msg == '顺口溜':
        send_text_msg(robot_wxid, to_wxid, tianxingapi.skl())
    elif msg == '舔狗日记':
        send_text_msg(robot_wxid, to_wxid, tianxingapi.tiangou())
    elif msg.startswith('藏头诗'):
        data = msg.replace('藏头诗','').strip()
        send_text_msg(robot_wxid, to_wxid, alapi.poem(data))
    elif msg.startswith('知乎历史') or msg.startswith('知乎往日'):
        data = msg.replace('知乎历史','').replace('知乎往日','').strip()
        if len(data) == 8:
            send_text_msg(robot_wxid, to_wxid, zhihu.historyzhihu(data))
        else:
            send_text_msg(robot_wxid, to_wxid, '日期格式不正确，示例：知乎历史 20210101')
    #语音合成
    elif msg.startswith('语音'):
        sentence = msg.replace('语音：','').replace('语音:','').replace('语音','').split('说');
        voice = 'xiaoyun'
        voice2 = getvoice(sentence[0].strip())
        if voice2 is not None and voice2.strip()!= '':
            voice = voice2
            print(voice)
        path = say(voice, sentence[1])
        send_file_msg(robot_wxid, to_wxid, path)
        send_group_at_msg(robot_wxid, to_wxid, final_from_wxid, final_nickname, saytail())
    elif msg.startswith('壁纸') or msg.startswith('高清壁纸'):
        send_image_msg(robot_wxid, to_wxid, bakground.getbgp())
    elif msg == '二次元':
        send_image_msg(robot_wxid, to_wxid, bakground.erciyuan())
    elif msg.startswith('强制点歌'):
        sentence = msg.replace('强制点歌：','').replace('强制点歌:','').replace('强制点歌','')
        music = netease.search(sentence)
        send_link_msg(robot_wxid, to_wxid, "网易云音乐", music, netease.getmusic(music[0]), music[1])
    elif msg.startswith('分享歌曲'):
        sentence = msg.replace('分享歌曲：','').replace('分享歌曲:','').replace('分享歌曲','')
        music = netease.search(sentence)
        send_text_msg(robot_wxid, to_wxid, netease.share(music[0]))
    elif msg.startswith('点歌'):
        sentence = msg.replace('点歌：','').replace('点歌:','').replace('点歌','')
        send_music_msg(robot_wxid, to_wxid, sentence)
        #send_link_msg(robot_wxid, to_wxid, "title", "text", netease.getmusic(210049), "http://www.w3.org/2000/svg")
        #send_file_msg(robot_wxid, to_wxid, netease.getmusic(210049))
        #send_text_msg(robot_wxid, to_wxid, netease.share(210049))
    elif msg == '豆瓣分类':
        send_text_msg(robot_wxid, to_wxid, movie.dbfl())
    elif msg.startswith('豆瓣'):
        info = msg.replace('豆瓣:','').replace('豆瓣','').strip()
        if ' ' not in info:
            send_text_msg(robot_wxid, to_wxid, movie.douban(info, 0))
        send_text_msg(robot_wxid, to_wxid,movie.douban(info.split(' ')[0].strip(), int(info.split(' ')[1].strip())-1))
    elif msg.startswith('电视剧'):
        info = msg.replace('电视剧','').strip()
        send_text_msg(robot_wxid, to_wxid,"请复制到浏览器打开")
        if ' ' not in info:
            send_text_msg(robot_wxid, to_wxid, movie.tvs(info, 0))
            #send_link_msg(robot_wxid, to_wxid, "电视剧", str(info)+" 第1集", movie.tvs(info, 0), "")
            return
        send_text_msg(robot_wxid, to_wxid, movie.tvs(info.split(' ')[0].strip(), int(info.split(' ')[1].strip())))
        #send_link_msg(robot_wxid, to_wxid, "电视剧", str(info.split(' ')[0].strip())+" 第%s集"%str(info.split(' ')[1].strip()), movie.tvs(info.split(' ')[0].strip(), int(info.split(' ')[1].strip())), "")
    else:
        res = robot.qingyunke(msg)
        res = str(res).replace("{br}", '\r\n')
        send_group_at_msg(robot_wxid, to_wxid, final_from_wxid, final_nickname, res)